package com.jfs.security.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jfs.result.Result;
import com.jfs.security.annotations.Log;
import com.jfs.security.annotations.LoginUser;
import com.jfs.security.dto.OperationLogDto;
import com.jfs.security.service.OperationLogService;
import com.jfs.security.vo.LogListVo;
import com.jfs.security.vo.LoginUserEntity;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Description 日志控制器
 * @E-mail cwm3412638@163.com
 * @Author cwm
 * @Date 2022/8/9
 */
@RestController
@RequestMapping("/log")
@AllArgsConstructor
public class LogController {
    private final OperationLogService operationLogService;

    /**
     * 获取当前用户操作日志信息 超级管理员获取所有信息
     *
     * @return
     */
    @Log(name = "获取当前用户操作信息")
    @GetMapping
    public Result<IPage<OperationLogDto>> list(@LoginUser LoginUserEntity loginUserEntity, LogListVo logListVo) {
        return Result.success("获取操作信息列表成功", this.operationLogService.list(loginUserEntity, logListVo));
    }

    /**
     * 如果是超级管理则清空所有信息 如果是普通用户清除自己的所有操作信息
     *
     * @param loginUserEntity
     * @return
     */
    @Log(name = "清空用户操作信息")
    @DeleteMapping
    public Result clean(@LoginUser LoginUserEntity loginUserEntity) {
        this.operationLogService.clean(loginUserEntity);
        return Result.success("清空操作日志成功", null);
    }
}
